﻿using Server.Attributes;
using Server.DTool;
using Server.Message;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Server.Manager
{
    [System]
    class TimeSystem
    {
        readonly TimeTaskScheduler _timeTaskScheduler = new();

        const int MS2TICK_UNIT = 10000;

        #region Ticks
        public static long GetTicks(int ms)
        {
            return ms * MS2TICK_UNIT;
        }

        public static long IncTicks(long tick, int ms)
        {
            return tick + ms * MS2TICK_UNIT;
        }

        public static long IncTicks(long tick, long ms)
        {
            return tick + ms * MS2TICK_UNIT;
        }
        public static long ReduceTicks(long tick, int ms)
        {
            return tick - ms * MS2TICK_UNIT;
        }
        public static long ReduceTicks(long tick, long ms)
        {
            return tick - ms * MS2TICK_UNIT;
        }

        public static long NextTicks(int intervalMs)
        {
            return DateTime.UtcNow.Ticks + intervalMs * MS2TICK_UNIT;
        }

        public static long NextTicks(long intervalMs)
        {
            return DateTime.UtcNow.Ticks + intervalMs * MS2TICK_UNIT;
        }
        #endregion

        void Init()
        {
            _timeTaskScheduler.Clear();
        }

        void Start()
        {
            _timeTaskScheduler.Start();
            Console.WriteLine("TimeManager 启动");

            MySystem.GetSystem<MsgSystem>().Send(Msg.GetRegMsg(MsgType.AddTimeTask, AddTimeTask));

        }

        void AddTimeTask(object obj)
        {

        }

    }
}
